<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>我要发货</title>
	<link rel="shortcut icon" href="https://gtms04.alicdn.com/tps/i4/TB1_oz6GVXXXXaFXpXXJDFnIXXX-64-64.ico" type="image/x-icon"/>
	<link rel="stylesheet" href="https://g.alicdn.com/thx/cube/1.3.2/cube.min.css">
	<link rel="stylesheet" href="/wjfh/css/iconfont.css">
	<link rel="stylesheet" type="text/css" href="/wjfh/css/common.css"/>
	<link rel="stylesheet" type="text/css" href="/wjfh/layui/css/layui.css"/>
	<link rel="stylesheet" type="text/css" href="/wjfh/css/style.css"/>
	<script src="/wjfh/js/flexible.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>

<div class="layui-form" id="fahuo" style="display: none;">

	<div class="resgcontain">
		<h1 class="site-h1">收货信息</h1>
		<div class="layui-tab layui-tab-brief">
			<div class="layui-form-item">

				<i class="layui-icon" style="color: #009688;vertical-align: bottom;">&#xe643;</i>
				<span class="layui-badge layui-bg-orange" style="background-color: inherit!important;color: #666!important;">{{goodsdata.name}}</span>
				<span class="layui-badge layui-bg-orange" style="">{{goodsdata.deptName}}</span>
			</div>
			<div class="item">
				<textarea placeholder="" class="publicIptSty widthman layui-input-disabled" v-model="goodsdata.address" readonly></textarea>
			</div>
		</div>
		<div class="item" style="margin-bottom: 0px;">
			<blockquote class="layui-elem-quote" style="padding: 5px">
				凭证截图
			</blockquote>
			<img style="display: none;" id="imgUrl" :src="goodsdata.img">
		</div>
	</div>
	<div class="cotpad">
		<fieldset class="layui-elem-field layui-field-title site-title">
			<legend><a name="compatibility">扫码出货</a></legend>
		</fieldset>
	</div>
	<div class="resgcontain">


		<div class="layui-tab layui-tab-brief">

			<div v-for="(goodsdatas,key) in goodsdata.data">

				<div class="item"></div>
				<div class="item">
					<div class="saomaiptbox">
						<input type="text" name="" class="layui-input layui-input-disabled" :value="goodsdatas.goodsName" autocomplete="off" placeholder="" disabled/>
						<span class="icon iconfont" style="font-size: 16px;">{{goodsdatas.goodsNum}}件</span>
					</div>
				</div>
				<div class="item">
					<div class="saomaiptbox">
						<textarea class="publicIptSty widthman erwemaarrval" :data-id="goodsdatas.goodsId" :data-len="goodsdatas.goodsNum" placeholder="二维码"></textarea>

						<span class="icon iconfont" :id="goodsdatas.goodsId" @click="openwxSaoma(goodsdatas.goodsId)">&#xe68c;</span>
					</div>

				</div>

			</div>


			<div class="item">
				<input type="text" class="publicIptSty widthman" value="" placeholder="运单编号"  v-model="postCode"/>
			</div>



		</div>
	</div>
	<div class="shangpd">
		<button class="layui-btn layui-btn-fluid resgSubmit" @click="fahuofun();">确认出货</button>
	</div>

</div>
<div class="pubfooter">
	<div class="layui-row">
		<div class="layui-col-xs3 tcenter footnav ">
			<a href="/goodsManager/page/index">
				<span class="layui-icon footicon">&#xe68e;</span>
				<div class="name">首页</div>
			</a>
		</div>
		<div class="layui-col-xs3 tcenter footnav">
			<a href="/goodsManager/page/ddgl">
				<span class="layui-icon footicon">&#xe656;</span>
				<div class="name">订单</div>
			</a>
		</div>
		<div class="layui-col-xs3 tcenter footnav">
			<a href="/goodsManager/page/myPer">
				<span class="icon iconfont footicon">&#xe623;</span>
				<div class="name">业绩</div>
			</a>
		</div>
		<div class="layui-col-xs3 tcenter footnav">
			<a href="/goodsManager/page/xiaji">
				<span class="layui-icon footicon">&#xe66f;</span>
				<div class="name">下级</div>
			</a>
		</div>
	</div>
</div>
<script src="/wjfh/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="/wjfh/js/vue.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/wjfh/js/axios.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/jquery.min.js?v=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
<script src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>

<script>

	window.onload = function () {
        var idata = new  Vue({
            el:"#fahuo",
            data:{
                goodsdata:{},
                tiaoxingma:'',
                postCode:'',
                orderCode:'',
                receiptName:'',
                isNone:'',
                goodss:{},
                textval:{},
				orderId:''

            },
            methods:{
                fahuofun:function () {
                    var len = 0;
                    var ddaa = idata.goodsdata.data;

                    for(goodsdata in idata.goodsdata.data){
                        var ids = idata.goodsdata.data[goodsdata].goodsId;
                        //var vals = document.getElementById(idata.goodsdata.data[goodsdata].goodsId).value;
                        var vals = [];
                        vals = $(".erwemaarrval[data-id ='"+idata.goodsdata.data[goodsdata].goodsId+"']").val().split(",");
                        var key = [ids];
                        //var key = [ids];
                        idata.goodss[key] = vals;
                    }
                    //console.log(JSON.stringify(idata.goodss));

                    var jsonStr = {
                        "orderId": idata.orderCode,
                        "ids":JSON.stringify(idata.goodss),
                        "postCode":idata.postCode
                    };

                    var param = {"jsonStr":JSON.stringify(jsonStr)};
                    console.log(jsonStr);
                    layer.ready(function(){
                        layer.load(1);
                    });
                    if($('.erwemaarrval').val() != ''){
                        $.ajax({
                            cache: true,
                            type: "POST",
                            data:jsonStr,
                            url: "/goodsManager/gmOrder/sendOrder",
                            error : function(request) {
                                layer.alert("Connection error");
                            },
                            success : function(data) {
                                if(data.code != 500){
                                    layer.msg('出货成功!', {icon: 6,time: 1200},function () {
                                        parent.location.href = '/goodsManager/page/ddgl';
                                    });
                                }else{
                                    layer.msg(data.msg, {icon:5,time: 2000});
                                }
                                console.log(data);

                            }
                        });
					}else{
                        layer.msg('请扫码或者输入二维码编号', {icon:5,time: 1200});
					}

                },
                openwxSaoma:function (id) {
                    wx.ready(function () {
                        wx.scanQRCode({
                            needResult: 1,
//                    		desc: 'scanQRCode desc',
                            scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有　　
                            success: function (res) {
                                var serialNumber = res.resultStr;
                                if(serialNumber.indexOf(',') > 0){
                                    var dealserialNumber=serialNumber.split(',')[1];
                                    dealserialNumber = dealserialNumber.replace(/[^a-z\d]/ig, "");
                                    idata.textval[id].push(dealserialNumber);

                                    var vv = '';
                                    for(ia in idata.textval[id]){
                                        vv += idata.textval[id][ia] + ",";
                                    }
                                    $('.erwemaarrval[data-id = "'+id+'"]').val(vv.substring(0, vv.lastIndexOf(',')));
                                    vv = '';
                                }else{

                                }
                            }
                        });

                    });
                }


            },
            mounted:function () {

                layui.use(['jquery', 'form','layer'], function() {
                    $ = layui.jquery,
                        form = layui.form,
                        layer = layui.layer;

                    //--------------------------扫码部分------------------------------

                    var link = location.href.split('#')[0];
                    $.ajax({
                        //cache: false,
                        type: "GET",
                        data:{"url":link},
                        url: "/wechat/wechatParam",
                        error : function(request) {
                            layer.alert("Connection error");
                        },
                        success : function(data) {
                            console.log(data);
                            wx.config({
                                debug: false,
                                appId: data.appid,
                                timestamp: data.timestamp,
                                nonceStr: data.nonceStr,
                                signature: data.signature,
                                jsApiList: [
                                    'checkJsApi',
                                    'onMenuShareTimeline',
                                    'onMenuShareAppMessage',
                                    'onMenuShareQQ',
                                    'onMenuShareWeibo',
                                    'hideMenuItems',
                                    'showMenuItems',
                                    'hideAllNonBaseMenuItem',
                                    'showAllNonBaseMenuItem',
                                    'translateVoice',
                                    'startRecord',
                                    'stopRecord',
                                    'onRecordEnd',
                                    'playVoice',
                                    'pauseVoice',
                                    'stopVoice',
                                    'uploadVoice',
                                    'downloadVoice',
                                    'chooseImage',
                                    'previewImage',
                                    'uploadImage',
                                    'downloadImage',
                                    'getNetworkType',
                                    'openLocation',
                                    'getLocation',
                                    'hideOptionMenu',
                                    'showOptionMenu',
                                    'closeWindow',
                                    'scanQRCode',
                                    'chooseWXPay',
                                    'openProductSpecificView',
                                    'addCard',
                                    'chooseCard',
                                    'openCard'
                                ]

                            });
                        }
                    });

                    var local = window.location.href,goodscode='';
                    goodscode = local.split('=')[1];
                    idata.orderCode = goodscode;
                    layer.ready(function(){
                        layer.load(1);
                    });
                    console.log(goodscode);
                    $.ajax({
                        cache: true,
                        type: "POST",
                        data:{orderId:goodscode},
                        url: "/goodsManager/gmOrder/getOrderOne",
                        error : function(request) {
                            layer.alert("Connection error");
                        },
                        success : function(data) {
                            idata.receiptName = data.receiptName;
                            idata.goodsdata = data;


                            for (gd in idata.goodsdata.data){
                                idata.textval[idata.goodsdata.data[gd].goodsId] = [];
							}
//                            idata.textval[6].push(123,123,123,22,22,33);
//                            idata.textval[6] = new Set(idata.textval[6]);
//                            for (var aa of idata.textval[6]){
//                                console.log(aa);
//							}

                            layer.closeAll('loading');
                            $("#fahuo").show();
                            if(data.img != ''){
                                $("#imgUrl").show();
                                $("#imgUrl").attr("src",data.img);

                            }
                            console.log(idata.goodsdata);
                            var idsarr=[];
                            for (goodsindex in idata.goodsdata.data){
                                idsarr.push(idata.goodsdata.data[goodsindex].goodsId)
                            }
                        }
                    });

                })
            }
        })
    }
</script>
</body>
</html>
